<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/* 
<span class='line'>  2</span>  * Timemap.js Copyright 2010 Nick Rabinowitz.
<span class='line'>  3</span>  * Licensed under the MIT License (see LICENSE.txt)
<span class='line'>  4</span>  */</span><span class="WHIT">
<span class='line'>  5</span> 
<span class='line'>  6</span> </span><span class="COMM">/**
<span class='line'>  7</span>  * @fileOverview
<span class='line'>  8</span>  * Progressive loader
<span class='line'>  9</span>  *
<span class='line'> 10</span>  * @author Nick Rabinowitz (www.nickrabinowitz.com)
<span class='line'> 11</span>  */</span><span class="WHIT">
<span class='line'> 12</span> </span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 13</span> </span><span class="COMM">// for JSLint</span><span class="WHIT">
<span class='line'> 14</span> </span><span class="COMM">/*global TimeMap */</span><span class="WHIT">
<span class='line'> 15</span> 
<span class='line'> 16</span> </span><span class="COMM">/**
<span class='line'> 17</span>  * @class
<span class='line'> 18</span>  * Progressive loader class - basically a wrapper for another remote loader that can
<span class='line'> 19</span>  * load data progressively by date range, depending on timeline position.
<span class='line'> 20</span>  *
<span class='line'> 21</span>  * &lt;p>The progressive loader can take either another loader or parameters for 
<span class='line'> 22</span>  * another loader. It expects a loader with a "url" attribute including placeholder
<span class='line'> 23</span>  * strings [start] and [end] for the start and end dates to retrieve. The assumption 
<span class='line'> 24</span>  * is that the data service can take start and end parameters and return the data for 
<span class='line'> 25</span>  * that date range.&lt;/p>
<span class='line'> 26</span>  *
<span class='line'> 27</span>  * @example
<span class='line'> 28</span> TimeMap.init({
<span class='line'> 29</span>     datasets: [
<span class='line'> 30</span>         {
<span class='line'> 31</span>             title: "Progressive JSONP Dataset",
<span class='line'> 32</span>             type: "progressive",
<span class='line'> 33</span>             options: {
<span class='line'> 34</span>                 type: "jsonp",
<span class='line'> 35</span>                 url: "http://www.test.com/getsomejson.php?start=[start]&end=[end]callback="
<span class='line'> 36</span>             }
<span class='line'> 37</span>         }
<span class='line'> 38</span>     ],
<span class='line'> 39</span>     // etc...
<span class='line'> 40</span> });
<span class='line'> 41</span>  *
<span class='line'> 42</span>  * @example
<span class='line'> 43</span> TimeMap.init({
<span class='line'> 44</span>     datasets: [
<span class='line'> 45</span>         {
<span class='line'> 46</span>             title: "Progressive KML Dataset",
<span class='line'> 47</span>             type: "progressive",
<span class='line'> 48</span>             options: {
<span class='line'> 49</span>                 loader: new TimeMap.loaders.kml({
<span class='line'> 50</span>                     url: "/mydata.kml?start=[start]&end=[end]"
<span class='line'> 51</span>                 })
<span class='line'> 52</span>             }
<span class='line'> 53</span>         }
<span class='line'> 54</span>     ],
<span class='line'> 55</span>     // etc...
<span class='line'> 56</span> }); 
<span class='line'> 57</span>  * @see &lt;a href="../../examples/progressive.html">Progressive Loader Example&lt;/a>
<span class='line'> 58</span>  *
<span class='line'> 59</span>  * @constructor
<span class='line'> 60</span>  * @param {Object} options          All options for the loader
<span class='line'> 61</span>  * @param {TimeMap.loaders.remote} [options.loader] Instantiated loader class (overrides "type")
<span class='line'> 62</span>  * @param {String} [options.type]                   Name of loader class to use
<span class='line'> 63</span>  * @param {String|Date} options.start               Start of initial date range, as date or string
<span class='line'> 64</span>  * @param {Number} options.interval                 Size in milliseconds of date ranges to load at a time
<span class='line'> 65</span>  * @param {String|Date} [options.dataMinDate]       Minimum date available in data (optional, will avoid
<span class='line'> 66</span>  *                                                  unnecessary service requests if supplied)
<span class='line'> 67</span>  * @param {String|Date} [options.dataMaxDate]       Maximum date available in data (optional, will avoid
<span class='line'> 68</span>  *                                                  unnecessary service requests if supplied)
<span class='line'> 69</span>  * @param {Function} [options.formatUrl]            Function taking (urlTemplate, start, end) and returning
<span class='line'> 70</span>  *                                                  a URL formatted as needed by the service
<span class='line'> 71</span>  * @param {Function} [options.formatDate={@link TimeMap.util.formatDate}]           
<span class='line'> 72</span>  *                                                  Function to turn a date into a string formatted
<span class='line'> 73</span>  *                                                  as needed by the service
<span class='line'> 74</span>  * @param {mixed} [options[...]]                    Other options needed by the "type" loader
<span class='line'> 75</span>  */</span><span class="WHIT">
<span class='line'> 76</span> </span><span class="NAME">TimeMap.loaders.progressive</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">options</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 77</span> </span><span class="WHIT">    </span><span class="COMM">// get loader</span><span class="WHIT">
<span class='line'> 78</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">loader</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">options.loader</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 79</span> </span><span class="WHIT">        </span><span class="NAME">type</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">options.type</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 80</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">loader</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 81</span> </span><span class="WHIT">        </span><span class="COMM">// get loader class</span><span class="WHIT">
<span class='line'> 82</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">loaderClass</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="PUNC">(</span><span class="NAME">type</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">'string'</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="NAME">TimeMap.loaders</span><span class="PUNC">[</span><span class="NAME">type</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">type</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 83</span> </span><span class="WHIT">        </span><span class="NAME">loader</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">loaderClass</span><span class="PUNC">(</span><span class="NAME">options</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 84</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 85</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'> 86</span> </span><span class="WHIT">    </span><span class="COMM">// save loader attributes</span><span class="WHIT">
<span class='line'> 87</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">baseUrl</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">loader.opts.url</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 88</span> </span><span class="WHIT">        </span><span class="NAME">baseLoadFunction</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">loader.load</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 89</span> </span><span class="WHIT">        </span><span class="NAME">interval</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">options.interval</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 90</span> </span><span class="WHIT">        </span><span class="NAME">formatDate</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">options.formatDate</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">TimeMap.util.formatDate</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT">        </span><span class="NAME">formatUrl</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">options.formatUrl</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">url</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">start</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">end</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT">            </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">url</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT">                </span><span class="PUNC">.</span><span class="NAME">replace</span><span class="PUNC">(</span><span class="STRN">'[start]'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">formatDate</span><span class="PUNC">(</span><span class="NAME">start</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 94</span> </span><span class="WHIT">                </span><span class="PUNC">.</span><span class="NAME">replace</span><span class="PUNC">(</span><span class="STRN">'[end]'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">formatDate</span><span class="PUNC">(</span><span class="NAME">end</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 95</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 96</span> </span><span class="WHIT">        </span><span class="NAME">parseDate</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">TimeMap.dateParsers.hybrid</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'> 97</span> </span><span class="WHIT">        </span><span class="NAME">zeroDate</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseDate</span><span class="PUNC">(</span><span class="NAME">options.start</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 98</span> </span><span class="WHIT">        </span><span class="NAME">dataMinDate</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseDate</span><span class="PUNC">(</span><span class="NAME">options.dataMinDate</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 99</span> </span><span class="WHIT">        </span><span class="NAME">dataMaxDate</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseDate</span><span class="PUNC">(</span><span class="NAME">options.dataMaxDate</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>100</span> </span><span class="WHIT">        </span><span class="NAME">loaded</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>101</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'>102</span> </span><span class="WHIT">    </span><span class="COMM">// We don't start with a TimeMap reference, so we need</span><span class="WHIT">
<span class='line'>103</span> </span><span class="WHIT">    </span><span class="COMM">// to stick the listener in on the first load() call</span><span class="WHIT">
<span class='line'>104</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">addListener</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">dataset</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>105</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">band</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">dataset.timemap.timeline.getBand</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>106</span> </span><span class="WHIT">        </span><span class="COMM">// add listener</span><span class="WHIT">
<span class='line'>107</span> </span><span class="WHIT">        </span><span class="NAME">band.addOnScrollListener</span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>108</span> </span><span class="WHIT">            </span><span class="COMM">// determine relevant blocks</span><span class="WHIT">
<span class='line'>109</span> </span><span class="WHIT">            </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">now</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">band.getCenterVisibleDate</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>110</span> </span><span class="WHIT">                </span><span class="NAME">currBlock</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">Math.floor</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">now.getTime</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">zeroDate.getTime</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">/</span><span class="WHIT"> </span><span class="NAME">interval</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>111</span> </span><span class="WHIT">                </span><span class="NAME">currBlockTime</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">zeroDate.getTime</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">interval</span><span class="WHIT"> </span><span class="PUNC">*</span><span class="WHIT"> </span><span class="NAME">currBlock</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>112</span> </span><span class="WHIT">                </span><span class="NAME">nextBlockTime</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">currBlockTime</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">interval</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>113</span> </span><span class="WHIT">                </span><span class="NAME">prevBlockTime</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">currBlockTime</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NAME">interval</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>114</span> </span><span class="WHIT">                </span><span class="COMM">// no callback necessary?</span><span class="WHIT">
<span class='line'>115</span> </span><span class="WHIT">                </span><span class="NAME">callback</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>116</span> </span><span class="WHIT">                    </span><span class="NAME">dataset.timemap.timeline.layout</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>117</span> </span><span class="WHIT">                </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>118</span> </span><span class="WHIT">            </span><span class="WHIT">
<span class='line'>119</span> </span><span class="WHIT">            </span><span class="COMM">// is the current block loaded?</span><span class="WHIT">
<span class='line'>120</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">dataMaxDate</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">currBlockTime</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">dataMaxDate.getTime</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT">
<span class='line'>121</span> </span><span class="WHIT">                </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">dataMinDate</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">currBlockTime</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NAME">dataMinDate.getTime</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT">
<span class='line'>122</span> </span><span class="WHIT">                </span><span class="PUNC">!</span><span class="NAME">loaded</span><span class="PUNC">[</span><span class="NAME">currBlock</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>123</span> </span><span class="WHIT">                </span><span class="COMM">// load it</span><span class="WHIT">
<span class='line'>124</span> </span><span class="WHIT">                </span><span class="COMM">// console.log("loading current block (" + currBlock + ")");</span><span class="WHIT">
<span class='line'>125</span> </span><span class="WHIT">                </span><span class="NAME">loader.load</span><span class="PUNC">(</span><span class="NAME">dataset</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Date</span><span class="PUNC">(</span><span class="NAME">currBlockTime</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">currBlock</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>126</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>127</span> </span><span class="WHIT">            </span><span class="COMM">// are we close enough to load the next block, and is it loaded?</span><span class="WHIT">
<span class='line'>128</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">nextBlockTime</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">band.getMaxDate</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">getTime</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT">
<span class='line'>129</span> </span><span class="WHIT">                </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">dataMaxDate</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">nextBlockTime</span><span class="WHIT"> </span><span class="PUNC">&lt;</span><span class="WHIT"> </span><span class="NAME">dataMaxDate.getTime</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT">
<span class='line'>130</span> </span><span class="WHIT">                </span><span class="PUNC">!</span><span class="NAME">loaded</span><span class="PUNC">[</span><span class="NAME">currBlock</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>131</span> </span><span class="WHIT">                </span><span class="COMM">// load next block</span><span class="WHIT">
<span class='line'>132</span> </span><span class="WHIT">                </span><span class="COMM">// console.log("loading next block (" + (currBlock + 1) + ")");</span><span class="WHIT">
<span class='line'>133</span> </span><span class="WHIT">                </span><span class="NAME">loader.load</span><span class="PUNC">(</span><span class="NAME">dataset</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Date</span><span class="PUNC">(</span><span class="NAME">nextBlockTime</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">currBlock</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>134</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>135</span> </span><span class="WHIT">            </span><span class="COMM">// are we close enough to load the previous block, and is it loaded?</span><span class="WHIT">
<span class='line'>136</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">prevBlockTime</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NAME">band.getMinDate</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">getTime</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT">
<span class='line'>137</span> </span><span class="WHIT">                </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">dataMinDate</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">prevBlockTime</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NAME">dataMinDate.getTime</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT">
<span class='line'>138</span> </span><span class="WHIT">                </span><span class="PUNC">!</span><span class="NAME">loaded</span><span class="PUNC">[</span><span class="NAME">currBlock</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">]</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>139</span> </span><span class="WHIT">                </span><span class="COMM">// load previous block</span><span class="WHIT">
<span class='line'>140</span> </span><span class="WHIT">                </span><span class="COMM">// console.log("loading prev block (" + (currBlock - 1)  + ")");</span><span class="WHIT">
<span class='line'>141</span> </span><span class="WHIT">                </span><span class="NAME">loader.load</span><span class="PUNC">(</span><span class="NAME">dataset</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Date</span><span class="PUNC">(</span><span class="NAME">prevBlockTime</span><span class="PUNC">)</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">currBlock</span><span class="WHIT"> </span><span class="PUNC">-</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>142</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>143</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>144</span> </span><span class="WHIT">        </span><span class="COMM">// kill this function so that listener is only added once</span><span class="WHIT">
<span class='line'>145</span> </span><span class="WHIT">        </span><span class="NAME">addListener</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>146</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>147</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'>148</span> </span><span class="WHIT">    </span><span class="COMM">/**
<span class='line'>149</span>      * Load data based on current time
<span class='line'>150</span>      * @name TimeMap.loaders.progressive#load
<span class='line'>151</span>      * @function
<span class='line'>152</span>      * @param {TimeMapDataset} dataset      Dataset to load data into
<span class='line'>153</span>      * @param {Function} callback           Callback to execute when data is loaded
<span class='line'>154</span>      * @param {Date} start                  Start date to load data from
<span class='line'>155</span>      * @param {Number} currBlock            Index of the current time block
<span class='line'>156</span>      */</span><span class="WHIT">
<span class='line'>157</span> </span><span class="WHIT">    </span><span class="NAME">loader.load</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">dataset</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">callback</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">start</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">currBlock</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>158</span> </span><span class="WHIT">        </span><span class="COMM">// set start date, defaulting to zero date</span><span class="WHIT">
<span class='line'>159</span> </span><span class="WHIT">        </span><span class="NAME">start</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">parseDate</span><span class="PUNC">(</span><span class="NAME">start</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NAME">zeroDate</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>160</span> </span><span class="WHIT">        </span><span class="COMM">// set current block, defaulting to 0</span><span class="WHIT">
<span class='line'>161</span> </span><span class="WHIT">        </span><span class="NAME">currBlock</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">currBlock</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="NUMB">0</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>162</span> </span><span class="WHIT">        </span><span class="COMM">// set end by interval</span><span class="WHIT">
<span class='line'>163</span> </span><span class="WHIT">        </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">end</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">Date</span><span class="PUNC">(</span><span class="NAME">start.getTime</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">interval</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>164</span> </span><span class="WHIT">        </span><span class="WHIT">
<span class='line'>165</span> </span><span class="WHIT">        </span><span class="COMM">// set current block as loaded</span><span class="WHIT">
<span class='line'>166</span> </span><span class="WHIT">        </span><span class="COMM">// XXX: Failed loads will give a false positive here...</span><span class="WHIT">
<span class='line'>167</span> </span><span class="WHIT">        </span><span class="COMM">// but I'm not sure how else to avoid multiple loads :(</span><span class="WHIT">
<span class='line'>168</span> </span><span class="WHIT">        </span><span class="NAME">loaded</span><span class="PUNC">[</span><span class="NAME">currBlock</span><span class="PUNC">]</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>169</span> </span><span class="WHIT">        </span><span class="WHIT">
<span class='line'>170</span> </span><span class="WHIT">        </span><span class="COMM">// put dates into URL</span><span class="WHIT">
<span class='line'>171</span> </span><span class="WHIT">        </span><span class="NAME">loader.opts.url</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">formatUrl</span><span class="PUNC">(</span><span class="NAME">baseUrl</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">start</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">end</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>172</span> </span><span class="WHIT">        </span><span class="WHIT">
<span class='line'>173</span> </span><span class="WHIT">        </span><span class="COMM">// load data</span><span class="WHIT">
<span class='line'>174</span> </span><span class="WHIT">        </span><span class="NAME">baseLoadFunction.call</span><span class="PUNC">(</span><span class="NAME">loader</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">dataset</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>175</span> </span><span class="WHIT">            </span><span class="COMM">// add onscroll listener if not yet done</span><span class="WHIT">
<span class='line'>176</span> </span><span class="WHIT">            </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="NAME">addListener</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>177</span> </span><span class="WHIT">                </span><span class="NAME">addListener</span><span class="PUNC">(</span><span class="NAME">dataset</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>178</span> </span><span class="WHIT">            </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>179</span> </span><span class="WHIT">            </span><span class="COMM">// run callback</span><span class="WHIT">
<span class='line'>180</span> </span><span class="WHIT">            </span><span class="NAME">callback</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>181</span> </span><span class="WHIT">        </span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>182</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>183</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'>184</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">loader</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>185</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>186</span> </span></pre></body></html>